﻿using STT.Business;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace STT.Profile.UserControlsHV
{
    public partial class UcChiTietTinNhan : System.Web.UI.UserControl
    {

        public DataTable tbUser;
        public DataTable tb;
        protected void Page_Load(object sender, EventArgs e)
        {

            tbUser = BTbDangNhap.SelectAllChatForHocVien(Session["TenDN"].ToString());

            LoadMessage();
        }

        void LoadMessage()
        {
            if (Request.QueryString["idmessage"] != null)
            {
                string idmessage = Request.QueryString["idmessage"].ToString().Trim();
                lvTinNhan.DataSource = BTbChat.SelectMessageForHocVien(Request.QueryString["idmessage"].ToString(), Session["TenDN"].ToString()).Tables[0];
                lvTinNhan.DataBind();
            }

        }
        protected void btSearch_Click(object sender, System.Web.UI.ImageClickEventArgs e)
        {
            tbUser = BTbDangNhap.SelectByName(txtTimKiem.Text);
        }

        protected void lvTinNhan_ItemCommand(object sender, System.Web.UI.WebControls.ListViewCommandEventArgs e)
        {
            if (e.CommandName == "Delete")
            {
                BTbChat.Delete(
                lvTinNhan.DataKeys[e.Item.DataItemIndex]["IdGui"].ToString().TrimEnd(), Session["TenDN"].ToString(),
                lvTinNhan.DataKeys[e.Item.DataItemIndex]["ThoiGianGui"].ToString().TrimEnd());
                ThongBao(lvTinNhan.DataKeys[e.Item.DataItemIndex]["IdNhan"].ToString().TrimEnd() + " " +
                    Session["TenDN"].ToString() + " " + lvTinNhan.DataKeys[e.Item.DataItemIndex]["ThoiGianGui"].ToString().TrimEnd());
                LoadMessage();
            }
        }

        void ThongBao(string Loi)
        {
            ScriptManager.RegisterClientScriptBlock(this, GetType(), "Thông báo!", "<script>alert('" + Loi + "')</script>", false);
        }

        protected void lvTinNhan_ItemDeleting(object sender, System.Web.UI.WebControls.ListViewDeleteEventArgs e)
        {

        }

        public string Display(string MaHV)
        {
            if (MaHV.TrimEnd() == Session["TenDN"].ToString())
                return "delete";
            return "hide";
        }
    }
}